﻿Public Class ctrTraCuuNV

    Private Sub ctrTraCuuNV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comboBox_Load()
        gridView_Load()
    End Sub

    Private Sub gridView_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvNhanVien.DataSource = bus.GetTable()
    End Sub

    Private Sub comboBox_Load()
        cmbGioiTinh.Items.Insert(0, "Nam")
        cmbGioiTinh.Items.Insert(1, "Nữ")
        cmbGioiTinh.Text = "Tất cả"

        cmbTinhTrang.Items.Insert(0, "Còn làm việc")
        cmbTinhTrang.Items.Insert(1, "Đã nghĩ việc")
        cmbTinhTrang.Text = "Tất cả"

        Dim bus1 As BangCapBUS = New BangCapBUS()
        cmbBangCap.DataSource = bus1.GetTable()
        cmbBangCap.DisplayMember = "TenBC"
        cmbBangCap.ValueMember = "MaBC"
        cmbBangCap.Text = "Tất cả"

        Dim bus2 As ChucVuBUS = New ChucVuBUS()
        cmbChucVu.DataSource = bus2.GetTable()
        cmbChucVu.DisplayMember = "TenCV"
        cmbChucVu.ValueMember = "MaCV"
        cmbChucVu.Text = "Tất cả"
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        frmMain.TabControl1.TabPages.Remove(frmMain.TabControl1.SelectedTab)
    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        Dim bus As GeneralBUS = New GeneralBUS()
        Dim str As String = "select * from NHANVIEN where HoTen like '%" + txtTimKiem.Text + "%' or DiaChi like '%" + txtTimKiem.Text + "%'"
        gvNhanVien.DataSource = bus.GetTable(str)
    End Sub

    Private Sub cmbTinhTrang_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTinhTrang.SelectionChangeCommitted
        Dim bus As GeneralBUS = New GeneralBUS()
        Dim str As String
        If (cmbTinhTrang.SelectedIndex = 0) Then
            str = "select * from NHANVIEN where TinhTrang=True"
        Else
            str = "select * from NHANVIEN where TinhTrang=False"
        End If

        gvNhanVien.DataSource = bus.GetTable(str)

        cmbChucVu.Text = "Tất cả"
        cmbGioiTinh.Text = "Tất cả"
        cmbBangCap.Text = "Tất cả"
    End Sub

    Private Sub cmbGioiTinh_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbGioiTinh.SelectionChangeCommitted
        Dim bus As GeneralBUS = New GeneralBUS()
        Dim str As String
        If cmbGioiTinh.SelectedIndex = 0 Then
            str = "select * from NHANVIEN where GioiTinh=False"
        Else
            str = "select * from NHANVIEN where GioiTinh=True"
        End If
        gvNhanVien.DataSource = bus.GetTable(str)

        cmbBangCap.Text = "Tất cả"
        cmbChucVu.Text = "Tất cả"
        cmbTinhTrang.Text = "Tất cả"
    End Sub

    Private Sub cmbBangCap_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBangCap.SelectionChangeCommitted
        Dim bus As GeneralBUS = New GeneralBUS()
        Dim str As String = "select * from NHANVIEN where MaBC=" + cmbBangCap.SelectedValue.ToString()
        gvNhanVien.DataSource = bus.GetTable(str)

        cmbChucVu.Text = "Tất cả"
        cmbGioiTinh.Text = "Tất cả"
        cmbTinhTrang.Text = "Tất cả"
    End Sub

    Private Sub cmbChucVu_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbChucVu.SelectionChangeCommitted
        Dim bus As GeneralBUS = New GeneralBUS()
        Dim str As String = "select * from NHANVIEN where MaCV=" + cmbChucVu.SelectedValue.ToString()
        gvNhanVien.DataSource = bus.GetTable(str)

        cmbBangCap.Text = "Tất cả"
        cmbGioiTinh.Text = "Tất cả"
        cmbTinhTrang.Text = "Tất cả"
    End Sub

    Private Sub gvNhanVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvNhanVien.SelectionChanged
        If gvNhanVien.CurrentRow IsNot Nothing Then
            Dim bus As GeneralBUS = New GeneralBUS()
            lbMaNV.Text = gvNhanVien.CurrentRow.Cells(0).Value.ToString()
            lbHoTen.Text = gvNhanVien.CurrentRow.Cells(1).Value.ToString()
            lbCMND.Text = gvNhanVien.CurrentRow.Cells(2).Value.ToString()
            If gvNhanVien.CurrentRow.Cells(3).Value = True Then lbGioiTinh.Text = "Nữ" Else lbGioiTinh.Text = "Nam"

            Dim ns As Date = gvNhanVien.CurrentRow.Cells(4).Value
            lbNgaySinh.Text = ns.Month.ToString() + "/" + ns.Day.ToString() + "/" + ns.Year.ToString()
            lbDiaChi.Text = gvNhanVien.CurrentRow.Cells(5).Value.ToString()
            lbDienThoai.Text = gvNhanVien.CurrentRow.Cells(6).Value.ToString()
            lbBangCap.Text = bus.GetValue("select TenBC from BANGCAP where MaBC=" + gvNhanVien.CurrentRow.Cells(7).Value.ToString())
            lbChucVu.Text = bus.GetValue("select TenCV from CHUCVU where MaCV=" + gvNhanVien.CurrentRow.Cells(8).Value.ToString())
            If gvNhanVien.CurrentRow.Cells(9).Value = True Then lbTinhTrang.Text = "Còn làm việc" Else lbTinhTrang.Text = "Đã nghĩ việc"
        End If
    End Sub

End Class
